<?php

class controller extends controllerBase {

	public function index()
	{
		//get all active modules
		$title = 'modules';
		
		$query = new Query("SELECT * FROM `modules` WHERE `active` = '1' AND `core` = '0'");
		
		
		$content .= '<h2>Active Modules</h2>';
		if($query->num_rows() > 0)
		{
			$modules = module::recordSet($query, 'module');
			
			foreach ($modules as $module)
			{
				$content .= '<p>' . $module->name . ' - <a href="' . ROOT_URL . 'admin/' . URL_BASE . 'module/deactivate/' . $module->id . '">Deactivate</a>';
			}
		}
		else
		{
			$content .= '<p>There are no active modules</p>';
		}
		
		$query = new Query("SELECT * FROM `modules` WHERE `core` = '1'");
		
		$content .='<h2>Core Modules</h2>';
		if($query->num_rows() > 0)
		{
			$modules = module::recordSet($query, 'module');
			foreach ($modules as $module)
			{
				$content .= '<p>' . $module->name .'</p>';
			}
		}
		else
		{
			$content .= '<p>There are no Core modules</p>';
		}
		
		
		$query = new Query("SELECT * FROM `modules` WHERE `active` = '0'");
		
		
		$content .= '<h2>Inactive Modules</h2>';
		if($query->num_rows() > 0)
		{
			$modules = module::recordSet($query, 'module');
			foreach ($modules as $module)
			{
				$content .= '<p>' . $module->name . ' - <a href="' . ROOT_URL . 'admin/' . URL_BASE . 'module/activate/' . $module->id . '">Activate</a>';
			}
		}
		else
		{
			$content .= '<p>There are no inactive modules</p>';
		}
		include(ROOT . 'admin/skin/wrapper.php');
	}
	
	/*
		activate a module
	*/
	public function activate($id)
	{
		$module = new module($id);
		$module->active = 1;
		$module->save();
		$content .= 'Module Activated';
		include(ROOT . 'admin/skin/wrapper.php');
	}
	
	/*
		deactivate a module
	*/
	public function deactivate($id)
	{
		$module = new module($id);
		$module->active = 0;
		$module->save();
		$content .= 'Module Deactivated';
		include(ROOT . 'admin/skin/wrapper.php');
	}
	
}
?>